﻿using System;
using HelpdeskServices.KmsWebReference;

/// <summary>
/// Summary description for Import
/// </summary>
internal class Import
{
    private readonly WebCaseCollection _webCases;

    /// <param name="parameters">Bounds within which to run import, to reduce unnessary processing time</param>
    public Import(ImportParameters parameters)
    {
        CRMService kalWebService = Common.KalahariManagmentSystemWebServiceProxy();

        CustomerFeedbackResults webCases = kalWebService.SearchCustomerFeedback(parameters.Date.ToString());

        WebCaseCollection caseCollection = new WebCaseCollection();

        foreach (CustomerFeedback webCase in webCases.CustomerFeedbacks)
        {
            try
            {
                WebCase webCaseDoesNotExistInCrm = new WebCase(webCase);
                webCaseDoesNotExistInCrm.Validate();
                caseCollection.Add(webCaseDoesNotExistInCrm);
            }
            catch (Exception error)
            {
                Common.LogErrorMessage(error);
            }
        }

        _webCases = caseCollection;
    }

    public WebCaseCollection WebCases
    {
        get { return _webCases; }
    }
}